// pages/search/search.js
Page({

  /**
   * 页面的初始数据
   */
  data: {

  },
  ssIpt(e) {
    // console.log(e.detail.value);
    this.setData({
      value: e.detail.value
    })
  },
  search1(e){
    let ssData = e.currentTarget.dataset.name
      console.log(ssData);
      wx.navigateTo({
        url: `../../searchResult/searchResult/searchResult?ssData=${ssData}`,
      })
  },
  search(e) {
    if (this.data.value) {
      console.log(e);
      let ssData = this.data.value || e.currentTarget.dataset.name
      console.log(ssData);
      let arr = wx.getStorageSync('recentSearch') || [];
      let res = arr.filter(function (item) {
        return item != ssData
      })
      wx.setStorageSync('recentSearch', [ssData, ...res])
      wx.navigateTo({
        url: `../../searchResult/searchResult/searchResult?ssData=${ssData}`,
      })
      this.setData({
        value: ''
      })
    } else {
      wx.showToast({
        title: '内容不能为空',
        icon:'error'
        // image:'../../img/search_img/jg.png'
      })
    }
  },
  hotNav(e) {
    console.log(e);
    wx.navigateTo({
      url: `../../detaiPage/detaiPage/detaiPage?index_id=${e.currentTarget.dataset.idx_id}`,
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.cloud.callFunction({
      name: 'solePage',
      data: {
        code: 2
      },
      success: (res) => {
        // console.log(res);
        this.setData({
          hot: res.result.data
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    let recentSearch = wx.getStorageSync('recentSearch')
    this.setData({
      recentSearch
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})